package obj;

import game.GameWin;
import utils.GameUtils;

import java.awt.*;

public class BulletObj extends GameObj {
        //标志该子弹是否会向左右偏移，用于BOSS；0为竖直发射，-1向左偏移，1向右偏移
    int grapeShot = 0;
    @Override
    public Image getImage() {
        return super.getImage();
    }

    public BulletObj(Image image, int x, int y, int width, int height, double speed, GameWin frame) {
        super(image, x, y, width, height, speed, frame);
    }

        public BulletObj(Image image, int x, int y, int width, int height, double speed, GameWin frame,int grapeShot) {
        super(image, x, y, width, height, speed, frame);
        this.grapeShot = grapeShot;
    }

    @Override
   public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);
        y += speed;
        if(grapeShot == 0){
            y += speed;
        }else if (grapeShot == -1){
            x -= speed;
            y += speed;
        }else if(grapeShot == 1){
            x += speed;
            y += speed;
        }

        //敌方子弹与我方飞机的碰撞检测
        if (this.getRec().intersects(this.frame.planeObj.getRec())) {
            GameWin.state = 3;
        }
        //敌方子弹的越界消失，条件：y>600，改变后的坐标（-300，300）
        if (y > 600) {
            this.x = -300;
            this.y = 300;
            GameUtils.removeList.add(this);
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
